
//读取配置文件
let path = require('path');
let q = require('q');
let fs = require('fs');
let xml = require('../../util/xmlRead.js');

// 导入日志模块
require('../../util/log4jsHandler.js');
//临时变量到时候替换到用户目录中
let writePath=path.resolve(__dirname,"../../dist/createTable.sql");

//加载全局配置
var content=fs.readFileSync(path.resolve(__dirname,"../../.configrc"));

global.selfConfig=JSON.parse(content);
global.selfConfig.writePath=writePath;


var xmlPromise=[];
// 读取所有的配置内容
// var root=path.resolve(__dirname,"../../conf/");
 var root=path.resolve(selfConfig.root,selfConfig.table_conf);//path.resolve(__dirname,"../../conf/");
// var root="E:\\springsts\\web01\\conf";
var tablesFile=fs.readdirSync(root+"/tables","utf8");
var typesFile=fs.readdirSync(root+"/types","utf8");

tablesFile.map(function(item){
	return path.resolve(root,"tables",item);
}).concat(typesFile.map(function(item){
	return path.resolve(root,"types",item);
})).forEach(function(item){
	xmlPromise.push(
	xml.read(item));
});

// 将所有table-xml的数据转成js对象
let promise=q.all(xmlPromise).then(function(arr){
	return arr;
}, function(err){
	console.log(err);
})




// 获取到配置文件内容并且作出一系列到数据处理
let tableHandler = require('../handler/TableDataHandler.js');

global.self={
	name:"mill"
}
// 获取tableHandler的处理结果
promise=tableHandler.handler(promise);
promise.then(function(data){
	// log(data);
	log("--------end-------");
},function(err){
	console.log(err);
});

// 生成建表sql
// 生成测试数据


